package com.knowledge.listenter;

import com.knowledge.common.cache.GlobalLocalCache;
import com.knowledge.listenter.event.CacheEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author zzz
 * @title: TokenCacheListener
 * @projectName knowledge-api
 * @description: TODO
 * @date 2022-03-05 19:08
 */
@Slf4j
@Component
public class TokenCacheListener {

     /**
     　* @description: 缓存清理监听
     　* @param ${tags}
     　* @return ${return_type}
     　* @throws
     　* @author zzz
     　* @date 2022-03-05 19:13
     */
    @Async("taskExecutor")
    @EventListener()
    public void cacheClear(CacheEvent cacheEvent){
        log.info("监听添加或更新token缓存事件，进行缓存清理工作...start......");
        GlobalLocalCache.clear(cacheEvent.getUserId(), cacheEvent.getTokenId());
        log.info("监听添加或更新token缓存事件，进行缓存清理工作...end......");
    }
}
